﻿hpxAdminApp.controller('billHoldingCenterController', function (exportService, $rootScope, $interval, $scope, $stateParams, $state, API_URL, NgTableParams, billService, constantsService, addressService, EXPORT_URL) {
    $scope.filter = {
        billType: '',
        acceptType: '',
        bill_sum_price_max: '',
        bill_sum_price_min: '',
        deadline_time_max: '',
        deadline_time_min: '',
        bill_status: '',
        bill_rate_min: '',
        bill_rate_max:''
    }
    $scope.model = {
        bill_price: '',
        bill_date: ''
    }
    //提取数字
    function extractNum(str) {
        str = str.replace(/[\u4E00-\u9FA5]/g, "")
        str = str.replace('(', ''),        str = str.replace(')', '');
        var str_before = str.split("-")[0];
        var str_after = str.split("-")[1];
        return [str_before, str_after];
    }

    //选择票面金额
    $scope.selectBillPrice = function () {
        $scope.filter.bill_sum_price_min = extractNum($scope.model.bill_price)[0];
        $scope.filter.bill_sum_price_max = extractNum($scope.model.bill_price)[1];
    }
    //选择到期期限   
    $scope.selectBillDate = function () {
        $scope.filter.deadline_time_min = extractNum($scope.model.bill_date)[0];
        $scope.filter.deadline_time_max = extractNum($scope.model.bill_date)[1];
    }
    $scope.tableParams = new NgTableParams({ 'sorting': { 'create_time': 'desc' } }, {
        getData: function (params) {
            return billService.billHoldingCenterList(params, $scope.filter).then(function (data) {
                $scope.first = $scope.getFirst(params);
                return data;
            });
        }
    });
    //刷新
    $scope.reflash = function () {
        $scope.tableParams.reload();
    }
    //获取电票汇票瑕疵信息
    constantsService.queryConstantsType(19).then(function (data) {
        $scope.billFlawData = data;
    })
    //设置瑕疵
    $scope.initBillFlaw = function () {
        if ($scope.models.bill_type_id == 101) {
            for (var i = 0; i < $scope.billFlawData.length; i++) {
                $scope.billFlawData[i].checked = false;
            }
            for (var i = 0; i < $scope.models.bill_flaw_ids.length; i++) {
                for (var j = 0; j < $scope.billFlawData.length; j++) {
                    if ($scope.models.bill_flaw_ids[i] == $scope.billFlawData[j].code) {
                        $scope.billFlawData[j].checked = true;
                    }
                }
            }
        }
        else {
            for (var i = 0; i < $scope.billFlawData2.length; i++) {
                $scope.billFlawData2[i].checked = false;
            }
            for (var i = 0; i < $scope.models.bill_flaw_ids.length; i++) {
                for (var j = 0; j < $scope.billFlawData2.length; j++) {
                    if ($scope.models.bill_flaw_ids[i] == $scope.billFlawData2[j].code) {
                        $scope.billFlawData2[j].checked = true;
                    }
                }
            }
        }
    }
    //电票，当选中无瑕疵时，其他选项均为false；反之，选中其他选项时，无瑕疵选项为false
    $scope.billFlawChange = function (item) {
        if (item.code == 1500) {
            item.checked = true;
            for (var i = 1; i < $scope.billFlawData.length; i++) {
                $scope.billFlawData[i].checked = false;
            }
        }
        else {
            for (var i = 0; i < $scope.billFlawData.length; i++) {
                if (i == 0) {
                    $scope.billFlawData[i].checked = true;
                }
                else {
                    if ($scope.billFlawData[i].checked) {
                        $scope.billFlawData[0].checked = false;
                    }
                }
            }
        }
    }

    //点击详细
    $scope.resd = function (item) {
        $scope.models = item;         //获取某条客户资料详细信息
        $scope.initBillFlaw();
        //弹出详细窗口
        $('#modal-read').modal('show');
        $('.jqzoom').imagezoom();       //图片放大功能
    };

});
